﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ActionConstraints;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Mvc.Routing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IM.Easy.Core.Route
{
    public class ImRouteConvention : IApplicationModelConvention
    {
        private readonly RouteGenerator _routeGenerator;
        public ImRouteConvention()
        {
            _routeGenerator = new RouteGenerator();
        }
        public void Apply(ApplicationModel application)
        {
            foreach (var controller in application.Controllers)
            {
                if (!_routeGenerator.IsApi(controller)) continue;
                _routeGenerator.ProcessControllerRoutes(controller);
                foreach (var action in controller.Actions)
                {
                    if (!_routeGenerator.IsRoute(action)) continue;
                    _routeGenerator.ProcessActionRoutes(action);

                }
            }
        }
    }
}
